import { hasVarString } from '@/interface'

type IRegTextName = '手机号' | '座机号' | '验证码' | '密码' | '身份证' | '护照' | '社会统一信用代码' | '银行卡号' | '邮政编码' | '中文姓名' | '英文姓名' | '车牌号' | '数字和字母' | '中文和数字' | '金额'

const RegEnum = {
    '手机号': /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-7|9])|(?:5[0-3|5-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1|8|9]))\d{8}$/,
    '座机号': /^\d{3}-\d{8}$|^\d{4}-\d{7}$/,
    '验证码': /^\d{6}$/,
    '密码': /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{8,}$/, // 密码至少8位，要求必须字母、数字加英文符号（不包含空格）
    '身份证': /(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0\d|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/,
    '护照': /(^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$)/,
    '社会统一信用代码': /^[0-9A-HJ-NPQRTUWXY]{2}\d{6}[0-9A-HJ-NPQRTUWXY]{10}$/,
    '银行卡号': /^\d{16,19}$/,
    '邮政编码': /^(0[1-7]|1[0-356]|2[0-7]|3[0-6]|4[0-7]|5[1-7]|6[1-7]|7[0-5]|8[013-6])\d{4}$/,
    '中文姓名': /^(?:[\u4e00-\u9fa5·]{2,16})$/,
    '英文姓名': /(^[a-zA-Z]{1}[a-zA-Z\s]{0,20}[a-zA-Z]{1}$)/,
    '车牌号': /^(?:[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-HJ-NP-Z]{1}(?:(?:[0-9]{5}[DF])|(?:[DF](?:[A-HJ-NP-Z0-9])[0-9]{4})))|(?:[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领 A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9 挂学警港澳]{1})$/,
    '数字和字母': /^[A-Za-z0-9]+$/,
    '金额': /^[0-9]+[.]?[0-9]{1,2}$/,
    '中文和数字': /^((?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])|(\d))+$/,
}
export const RegText = (reg: RegExp | IRegTextName, str: string) => {
    if (hasVarString(reg)) return RegEnum[reg as IRegTextName].test(str)
    return (reg as RegExp).test(str)
}
export default RegEnum
